package com.sunyard.pcc.common.shiro;

import com.sunyard.pcc.common.bo.SysUserCacheBO;
import com.sunyard.pcc.common.exception.PccCommonException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * @Author: Hewei
 * @Description: 用户存储接口
 * @Date: Created in 15:39 2018/3/12
 */
public interface UserSaveService {

    /**
     * 获取登录用户完整信息
     * @return
     * @throws PccCommonException
     */
    SysUserCacheBO getCacheUser() throws PccCommonException;

    /**
     * 对用户进行缓存
     * @param user
     * @throws PccCommonException
     */
    void saveUser(SysUserCacheBO user) throws PccCommonException;

    /**
     * 对缓存用户进行删除
     * @throws PccCommonException
     */
    void removeUser() throws PccCommonException;


    /**
     * 获取Session
     * @return
     */
    default Session getSession(){
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession(false);
        if (session == null){
            session = subject.getSession();
        }
        if (session != null){
            return session;
        }

        return null;
    }

}
